package my.algorithms;

/**
 * Created by IntelliJ IDEA.
 * User: jtruelove
 * Date: 4/2/11
 * Time: 8:04 AM
 * To change this template use File | Settings | File Templates.
 */
public class IsPrime
{
    public void runEratosthenesSieve(int upperBound)
    {
        int upperBoundSquareRoot = (int) Math.sqrt(upperBound);
        boolean[] isComposite = new boolean[upperBound + 1];
        for (int m = 2; m <= upperBoundSquareRoot; m++)
        {
            if (!isComposite[m])
            {
                System.out.print(m + " ");
                for (int k = m * m; k <= upperBound; k += m)
                {
                    isComposite[k] = true;
                }
            }
        }
        for (int m = upperBoundSquareRoot; m <= upperBound; m++)
        {
            if (!isComposite[m])
                System.out.print(m + " ");
        }
    }
}
